import { AnyAction } from "redux";
import produce from "immer";
// import * as types from "@/redux/mutation-types";
interface DataType {
	key: React.Key;
	menuName: string;
	sort: string;
	permission: string;
	component: string;
	componentName: string;
	path: string;
	keepAlive: string;
	alwaysShow: Boolean;
	visible: Boolean;
	managerMenu: string;
	status: number;
	menuType: number;
	icon: string;
	children?: DataType[];
}
interface MenuState {
	addUpdate: boolean;
	managerMenu: string;
	isModalOpen: boolean;
	fieldsValue: DataType;
}
const menuState: MenuState = {
	addUpdate: false,
	managerMenu: "",
	isModalOpen: false,
	fieldsValue: {
		key: "",
		menuName: "",
		sort: "",
		permission: "",
		component: "",
		componentName: "",
		path: "",
		keepAlive: "",
		alwaysShow: false,
		visible: false,
		managerMenu: "",
		status: 0,
		menuType: 0,
		icon: ""
	}
};

// menu reducer
const menu = (state: MenuState = menuState, action: AnyAction) =>
	produce(state, draftState => {
		switch (action.type) {
			case "UPDATE_ADDUPDATE":
				draftState.addUpdate = action.addUpdate;
				break;
			case "UPDATE_MANAGERMENU":
				draftState.managerMenu = action.managerMenu;
				break;
			case "UPDATE_FIELDSVALUE":
				draftState.fieldsValue = action.fieldsValue;
				break;
			case "UPDATE_ISMODALOPEN":
				draftState.isModalOpen = action.isModalOpen;
				break;
			default:
				return draftState;
		}
	});

export default menu;
